import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/pages/Home.vue'
import Category from '@/pages/Category.vue'
import Shopcart from '@/pages/Shopcart.vue'
import User from '@/pages/User.vue'

import GoodsList from '@/pages/goods/GoodsList.vue'
import Login from '@/pages/user/Login.vue'
import Register from '@/pages/user/Register.vue'
import GoodsInfo from '@/pages/goods/GoodsInfo.vue'

// import BScroll from 'better-scroll';
// new BScroll ('.menu-right',{
//   mouseWheel: true,
//   click:true,
//   probeType:3
// })
// BScroll.on('scroll',()=>{})
// import { computed } from 'vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [

    { path: '/', name:'home', redirect: '/home' },
    //{ path: '/', redirect: '/home', meta: { title: '⾸⻚' } },
    { path: '/home', component: Home, name: 'home', meta: { title: '⾸⻚' } },
    { path: '/category', component: Category, name: 'category', meta: { title: '分类' } },
    { path: '/shopcart', component: Shopcart, name: 'shopcart', meta: { title: '购物⻋' } },
    { path: '/user', component: User, name: 'user', meta: { title: '我的' }},
    { path: '/user/register', component: Register, name: 'register', meta: { title: '注册' }},
    { path: '/user/login', component: Login, name: 'login', meta: { title: '登录' }},
    { path: '/goodslist/:category_id', component:GoodsList, props:true,name: 'goodslist', meta: { title: '商品列表' }},
    {path:'/goodsinfo/:id',component: GoodsInfo, name:'goodsinfo',props:true,meta:{title:'商品详情'}},
  ]
  
 
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

// const isHomePage = computed(() => 
//   {
//   return route.path == '/home'
//   })

export default router
